// 获取全局应用程序实例对象
var app = getApp();
//引入网络库
import { get, post } from "../../util/util.js"

// 创建页面实例对象
Page({
  /**  
   * 页面名称 
   */
  name: "index",
  /**
   * 页面的初始数据
   */

  data: {
    uid: '',
    duration: 500,
    indicatorDots: true,
    autoplay: true,
    interval: 4000,
    //上下拉
    newlist: {},
    pagesize: 1,
    loading: false,
    defaulImg: "http://wolaimage-10029986.image.myqcloud.com/1-2016051421050035278.png"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {

  },

  /**
   * 数据获取
   */
  onLoad: function () {
    var that = this;
    wx.getStorage({
      key: 'login',
      success: function (res) {
        var data = res.data
        that.setData({
          uid: data.data.uid
        });
      },
    })
    //banner数据请求  
    post("/com/getFilmBanner", {}).then(data => {
      console.log('baner数据====================' + JSON.stringify(data.data));
      that.setData({
        bannerItems: data.data
      })
    })

    //推荐艺人数据获取
    post("/actor/ranklist", {}).then(data => {
      console.log('推荐艺人数据获取====================' + JSON.stringify(data.data));
      that.setData({
        yrItems: data.data
      })
    })
    post("/film/baselist", { page: 1, pagesize: 100 }).then(data => {
      console.log('首页剧组数据获取====================' + JSON.stringify(data.data));
      that.setData({
        pagesize: 1,
        newlist: data.data
      })
    })
  },

  onReachBottom: function () {
    var that = this
    that.setData({
      page: ++that.data.pagesize,
      loading: true
    })
    post("/actor/baselist", { page: that.data.pagesize, pagesize: 2 }).then(data => {
      console.log('首页艺人数据获取====================' + JSON.stringify(data.data));
      that.setData({
        loading: false,
        newlist: that.data.newlist.concat(data.data)
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.log('下拉刷新====================');
    this.onLoad()
    wx.stopPullDownRefresh()
  },
  search: function () {
    wx.navigateTo({
      url: '../search/search'
    })
  },
  onSwiperTab: function (event) {
    var that = this;
    var postid = event.currentTarget.dataset.postid;
    var postsid = event.currentTarget.dataset.postsid;
    var posturl = event.currentTarget.dataset.posturl;
    if (postid == '1') {//，1=sid为剧组id，2=sid艺人id，3=sid无效，url为跳转的网页地址
      wx.navigateTo({
        url: '../moviedetial/moviedetial?Uid=' + that.data.uid + '&Fid=' + postsid,
      })
    } else if (postid == '2') {
      wx.navigateTo({
        url: '../yirendetail/yirendetail?Touid=' + postsid + '&Myuid=' + that.data.uid,
      })
    } else if (postid == '3') {
      wx.navigateTo({
        url: '../web/web?Url=' + posturl,
      })
    }
  }
})

